// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: bk_file.cpp
// Description: BkFile Class
//      Author: Ziming Li
//     Created: 2020-06-03
// -------------------------------------------------
// Copyright (C) 2020 MingYang Software Technology.
// -------------------------------------------------

#include "./bk_file.h"

#include "third_party/zed/include/zed/file/file.hpp"

namespace BlinKit {

int BkFile::ReadContent(const BkPathChar *fileName, BkBuffer *dst)
{
    if (auto f = zed::file::open(fileName, zed::file::mode_t::open_existing))
    {
        const size_t size = f.size();
        if (size > 0)
        {
            const size_t r = f.read(dst->Allocator(size, dst->UserData), size);
            ZASSERT(r == size);
        }
        return BK_ERR_SUCCESS;
    }
    return BK_ERR_NOT_FOUND;
}

} // namespace BlinKit
